<?php


class Home extends AdminBase {

	public function index(){
	  $data['goods']=$this->db->get('goods')->result_array();
	  $data['list']=$this->db->get('index_goods')->result_array();
	   $this->load->view('home/index',$data);
	}



    public function add(){
  	$post=$this->input->post();
    	
 $this->db->trans_begin();
 foreach ($post['id'] as $k=>$v) {
 	 $where['id']=$v;
     $data['goods_id']=$post['goods_id'][$k];
 	 $data['img_id']=$post['img_id'][$k];
 	 $data['url']=$post['url'][$k];
 	 $this->db->where($where)->update('index_goods',$data);

 }
 

if ($this->db->trans_status() === FALSE){
    $this->db->trans_rollback();
  $this->show(array('code'=>0,'msg'=>'更新失败'));
}else{
    $this->db->trans_commit();
    $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
	$this->cache->delete('index_goods');
  $this->show(array('code'=>1,'msg'=>'更新成功'));			
}
     
    	
    	
    }

    
    public function video(){
    $data['video']=$this->db->get('video')->row_array();
    $data['video']['url']=$data['video']['url'];
    $this->load->view('home/video',$data);	
    }

    
    public function uploadvideo(){
    	$pathurl='video/'.date('Y-m-d');
		if (!file_exists($pathurl)) {
			mkdir($pathurl,0777,true);
		}
		$config['upload_path']      = $pathurl;
		$config['allowed_types']    ='mp4|avi';
		$config['file_name']    =date('Ymd',time()).uniqid();
		$config['max_size']     = 204800;
		$this->load->library('upload', $config);
		if (!$this->upload->do_upload('file')) {
			$data = array('code'=>0,'error'=>$this->upload->display_errors());
		} else {
			$data = array('code'=>1,'url'=>$pathurl.'/'.$config['file_name'],'upload_data'=>$this->upload->data());
		}
	
			if ($data['code']==1){
			$file['url']=$data['url'].$data['upload_data']['file_ext'];
			$file['ext']=$data['upload_data']['file_ext'];
			$this->db->update('video', $file);
			$this->show(array('code'=>1,'url'=>'/'.$file['url'],'msg'=>'上传成功'));
		}else{
			$this->show(array('code'=>0,'msg'=>'上传失败'));
		}
	
    }


}
